package com.abel.bigwater.tlv.model

import org.junit.Test
import org.slf4j.LoggerFactory
import kotlin.test.assertEquals

class TlvHelperTest {
    private val log = LoggerFactory.getLogger(TlvHelperTest::class.java)

    @Test
    fun testArray() {
        val ba = TlvHelper.fillTimestamp(ByteArray(6))
        log.info("bcd string: ${TlvHelper.toBcdString(ba)}")
        log.info("hex string: ${TlvHelper.toHexString(ba)}")
        log.info("hex string: ${TlvHelper.toHexString(ba, null)}")

        val ba2 = TlvHelper.toByteArray("18 03 22 13 40 52 BC CD")
        val str2 = TlvHelper.toHexString(ba2).trim().toUpperCase()
        log.info("rewind: ${str2}")
        assertEquals("18 03 22 13 40 52 BC CD", str2, "should be same as original")
    }

    @Test
    fun testCipher() {
        val ba = TlvHelper.toByteArray("""
            6f 76 62 3e f6 18 c4 fb 84 93 3b 0b d5 bf 59 e5 95 9e c8 da 18 98 cf e6 0f 05 0f 71 c7 72 0d aa 40 97 20 b2 e5 d7 a1 7a bd 16 40 da 09 09 1d 69 15 54 b9 da af 98 3f 11 15 74 0e f3 8d 0f 25 7e e2 9d 17 f1 e5 be cc c4 ca d0 1e ed 99 c9 e9 0c 4f 22 0c 1a 96 c9 ac d1 40 a1 38 33 93 2e 7e 61 42 2c 33 ff 6f c4 74 4e fb 48 bf eb 91 50 05 d0 42 2c 33 ff 6f c4 74 4e fb 48 bf eb 91 50 05 d0 42 2c 33 ff 6f c4 74 4e fb 48 bf eb 91 50 05 d0
        """)

        log.info("Plain text: {}", TlvHelper.toHexString(TlvHelper.decryptAes(ba)))
    }
}